
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Django入门与实践-第26章：个性化设置 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Deployment.html" />
    
    
    <link rel="prev" href="ClassBasedViews3.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="GettingStarted.html">
            
                <a href="GettingStarted.html">
            
                    
                    Django入门与实践-第1章：环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="GettingStarted-2.html">
            
                <a href="GettingStarted-2.html">
            
                    
                    Django入门与实践-第2章：创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="gettingstarted-3.html">
            
                <a href="gettingstarted-3.html">
            
                    
                    Django入门与实践-第3章：Hello World
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Fundamentals-1.html">
            
                <a href="Fundamentals-1.html">
            
                    
                    Django入门与实践-第4章：系统设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Fundamentals-2.html">
            
                <a href="Fundamentals-2.html">
            
                    
                    Django入门与实践-第5章：模型设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Fundamentals-3-0.html">
            
                <a href="Fundamentals-3-0.html">
            
                    
                    Django入门与实践-第6章：第一个视图函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Fundamentals-3-1.html">
            
                <a href="Fundamentals-3-1.html">
            
                    
                    Django入门与实践-第7章：模板引擎设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Fundamentals-3-1-1.html">
            
                <a href="Fundamentals-3-1-1.html">
            
                    
                    Django入门与实践-第8章：第一个单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="Fundamentals-3-2.html">
            
                <a href="Fundamentals-3-2.html">
            
                    
                    Django入门与实践-第9章：静态文件设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="Fundamentals-4.html">
            
                <a href="Fundamentals-4.html">
            
                    
                    Django入门与实践-第10章：Django Admin 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="AdvancedConcepts.html">
            
                <a href="AdvancedConcepts.html">
            
                    
                    Django入门与实践-第11章：URL 分发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="AdvancedConcept2.html">
            
                <a href="AdvancedConcept2.html">
            
                    
                    Django入门与实践-第12章：复用模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="AdvancedConcept3.html">
            
                <a href="AdvancedConcept3.html">
            
                    
                    Django入门与实践-第13章：表单处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="Authentication0.html">
            
                <a href="Authentication0.html">
            
                    
                    Django入门与实践-第14章：用户注册
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="Authentication1.html">
            
                <a href="Authentication1.html">
            
                    
                    Django入门与实践-第15章：用户注销
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="Authentication2.html">
            
                <a href="Authentication2.html">
            
                    
                    Django入门与实践-第16章：用户登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="DjangoORM0.html">
            
                <a href="DjangoORM0.html">
            
                    
                    Django入门与实践-第17章：保护视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="DjangoORM1.html">
            
                <a href="DjangoORM1.html">
            
                    
                    Django入门与实践-第18章：实现主题回复列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="DjangoORM2.html">
            
                <a href="DjangoORM2.html">
            
                    
                    Django入门与实践-第19章：实现主题回复功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="DjangoORM3.html">
            
                <a href="DjangoORM3.html">
            
                    
                    Django入门与实践-第20章：查询结果集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="DjangoORM.html">
            
                <a href="DjangoORM.html">
            
                    
                    Django入门与实践-第21章：Django数据迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="ClassBasedViews0.html">
            
                <a href="ClassBasedViews0.html">
            
                    
                    Django入门与实践-第22章：基于类的视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="ClassBasedViews1.html">
            
                <a href="ClassBasedViews1.html">
            
                    
                    Django入门与实践-第23章：分页实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="ClassBasedViews2.html">
            
                <a href="ClassBasedViews2.html">
            
                    
                    Django入门与实践-第24章：我的账户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ClassBasedViews3.html">
            
                <a href="ClassBasedViews3.html">
            
                    
                    Django入门与实践-第25章：Markdown支持
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.27" data-path="ClassBasedViews4.html">
            
                <a href="ClassBasedViews4.html">
            
                    
                    Django入门与实践-第26章：个性化设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="Deployment.html">
            
                <a href="Deployment.html">
            
                    
                    Django入门与实践-第27章：项目部署
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Django入门与实践-第26章：个性化设置</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;26&#x7AE0;&#xFF1A;&#x4E2A;&#x6027;&#x5316;&#x5DE5;&#x5177;">Django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;26&#x7AE0;&#xFF1A;&#x4E2A;&#x6027;&#x5316;&#x5DE5;&#x5177;</h1>
<p>&#x6211;&#x89C9;&#x5F97;&#x53EA;&#x6DFB;&#x52A0;&#x5185;&#x7F6E;&#x7684;&#x4EBA;&#x6027;&#x5316;(<strong>humanize</strong>)&#x5305;&#x5C31;&#x4F1A;&#x5F88;&#x4E0D;&#x9519;&#x3002;&#x5B83;&#x5305;&#x542B;&#x4E00;&#x7EC4;&#x4E3A;&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x201C;&#x4EBA;&#x6027;&#x5316;&#xFF08;human touch&#xFF09;&#x201D;&#x7684;&#x5DE5;&#x5177;&#x96C6;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5B83;&#x6765;&#x66F4;&#x81EA;&#x7136;&#x5730;&#x663E;&#x793A;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x5B57;&#x6BB5;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x5730;&#x663E;&#x793A;&#xFF1A;&#x201C;2&#x5206;&#x949F;&#x524D;&#x201D;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x663E;&#x793A;&#x6574;&#x4E2A;&#x65E5;&#x671F;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x6765;&#x5B9E;&#x8DF5;&#x4E00;&#x4E0B;&#xFF01;&#x9996;&#x5148;&#xFF0C;&#x6DFB;&#x52A0; <code>django.contrib.humanize</code> &#x5230;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684; <code>INSTALLED_APPS</code> &#x4E2D;&#x3002;</p>
<p><strong>myproject/settings.py</strong></p>
<pre><code class="lang-python">INSTALLED_APPS = [
    <span class="hljs-string">&apos;django.contrib.admin&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.auth&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.contenttypes&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.sessions&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.messages&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.staticfiles&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.humanize&apos;</span>,  <span class="hljs-comment"># &lt;- &#x8FD9;&#x91CC;</span>

    <span class="hljs-string">&apos;widget_tweaks&apos;</span>,

    <span class="hljs-string">&apos;accounts&apos;</span>,
    <span class="hljs-string">&apos;boards&apos;</span>,
]
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x4F7F;&#x7528;&#x5B83;&#x4E86;&#x3002;&#x9996;&#x5148;&#x6765;&#x7F16;&#x8F91; <strong>topics.html</strong> &#x6A21;&#x677F;:</p>
<p><strong>templates/topics.html</strong> <a href="https://gist.github.com/vitorfs/45521a289677a1a406b4fb743e8141ee" target="_blank">&#x67E5;&#x770B;&#x5B8C;&#x6574;&#x6587;&#x4EF6;</a></p>
<pre><code class="lang-html">
{% extends &apos;base.html&apos; %}

{% load humanize %}

{% block content %}
  <span class="hljs-comment">&lt;!-- &#x4EE3;&#x7801;&#x88AB;&#x538B;&#x7F29; --&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ topic.last_updated|naturaltime }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>

  <span class="hljs-comment">&lt;!-- &#x4EE3;&#x7801;&#x88AB;&#x538B;&#x7F29; --&gt;</span>
{% endblock %}
</code></pre>
<p>&#x6211;&#x4EEC;&#x6240;&#x8981;&#x505A;&#x7684;&#x5C31;&#x662F;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x52A0;&#x8F7D; <code>{&#xFF05;load humanize&#xFF05;}</code> &#x8FD9;&#x4E2A;&#x6A21;&#x677F;&#x6807;&#x7B7E;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x4F7F;&#x7528;&#x8FC7;&#x6EE4;&#x5668;&#xFF1A; <code>{{ topic.last_updated|naturaltime }}</code></p>
<p><img src="statics/6-12.png" alt=""></p>
<p>&#x4F60;&#x5F53;&#x7136;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x6DFB;&#x52A0;&#x5230;&#x5176;&#x4ED6;&#x4F60;&#x9700;&#x8981;&#x7684;&#x5730;&#x65B9;&#x3002;</p>
<h3 id="gravatar&#x6DFB;&#x52A0;&#x5934;&#x50CF;&#x7528;&#x7684;&#x5E93;">Gravatar(&#x6DFB;&#x52A0;&#x5934;&#x50CF;&#x7528;&#x7684;&#x5E93;)</h3>
<p>&#x7ED9;&#x7528;&#x6237;&#x4E2A;&#x4EBA;&#x4FE1;&#x606F;&#x6DFB;&#x52A0;&#x56FE;&#x7247;&#x7684;&#x4E00;&#x79CD;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x4F7F;&#x7528; <strong><a href="https://gravatar.com/" target="_blank">Gravatar</a></strong>&#x3002;</p>
<p>&#x5728; <strong>boards/templatetags</strong> &#x6587;&#x4EF6;&#x5939;&#x5185;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <strong>gravatar.py</strong> &#x7684;&#x65B0;&#x6587;&#x4EF6;&#xFF1A;</p>
<p><strong>boards/templatetags/gravatar.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> hashlib
<span class="hljs-keyword">from</span> urllib.parse <span class="hljs-keyword">import</span> urlencode

<span class="hljs-keyword">from</span> django <span class="hljs-keyword">import</span> template
<span class="hljs-keyword">from</span> django.conf <span class="hljs-keyword">import</span> settings

register = template.Library()


<span class="hljs-meta">@register.filter</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">gravatar</span><span class="hljs-params">(user)</span>:</span>
    email = user.email.lower().encode(<span class="hljs-string">&apos;utf-8&apos;</span>)
    default = <span class="hljs-string">&apos;mm&apos;</span>
    size = <span class="hljs-number">256</span>
    url = <span class="hljs-string">&apos;https://www.gravatar.com/avatar/{md5}?{params}&apos;</span>.format(
        md5=hashlib.md5(email).hexdigest(),
        params=urlencode({<span class="hljs-string">&apos;d&apos;</span>: default, <span class="hljs-string">&apos;s&apos;</span>: str(size)})
    )
    <span class="hljs-keyword">return</span> url
</code></pre>
<p>&#x57FA;&#x672C;&#x4E0A;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<a href="https://fi.gravatar.com/site/implement/images/python/" target="_blank">&#x5B98;&#x65B9;&#x63D0;&#x4F9B;&#x7684;&#x4EE3;&#x7801;&#x7247;&#x6BB5;</a>&#x3002;&#x6211;&#x53EA;&#x662F;&#x505A;&#x4E86;&#x4E00;&#x4E0B;&#x9002;&#x914D;&#xFF0C;&#x4F7F;&#x5F97;&#x5B83;&#x53EF;&#x4EE5;&#x5728;python 3&#x73AF;&#x5883;&#x4E2D;&#x8FD0;&#x884C;&#x3002;</p>
<p>&#x5F88;&#x597D;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x52A0;&#x8F7D;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x5C31;&#x50CF;&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4EBA;&#x6027;&#x5316;&#x6A21;&#x677F;&#x8FC7;&#x6EE4;&#x5668;&#x4E00;&#x6837;&#xFF1A;</p>
<p><strong>templates/topic_posts.html</strong> <a href="https://gist.github.com/vitorfs/23d5c5bc9e6c7ac94506a2660a61012c" target="_blank">&#x67E5;&#x770B;&#x5B8C;&#x6574;&#x6587;&#x4EF6;</a></p>
<pre><code class="lang-html">
{% extends &apos;base.html&apos; %}

{% load gravatar %}

{% block content %}
  <span class="hljs-comment">&lt;!-- code suppressed --&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;{{ post.created_by|gravatar }}&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;{{ post.created_by.username }}&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;w-100 rounded&quot;</span>&gt;</span>

  <span class="hljs-comment">&lt;!-- code suppressed --&gt;</span>
{% endblock %}
</code></pre>
<p><img src="statics/6-13.png" alt=""></p>
<h3 id="&#x6700;&#x540E;&#x8C03;&#x6574;">&#x6700;&#x540E;&#x8C03;&#x6574;</h3>
<p>&#x4E5F;&#x8BB8;&#x4F60;&#x5DF2;&#x7ECF;&#x6CE8;&#x610F;&#x5230;&#x4E86;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x4EBA;&#x56DE;&#x590D;&#x5E16;&#x5B50;&#x65F6;&#x6709;&#x4E00;&#x4E2A;&#x5C0F;&#x95EE;&#x9898;&#x3002;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x66F4;&#x65B0; <code>last_update</code> &#x5B57;&#x6BB5;&#xFF0C;&#x56E0;&#x6B64;&#x4E3B;&#x9898;&#x7684;&#x6392;&#x5E8F;&#x88AB;&#x6253;&#x4E71;&#x987A;&#x5E8F;&#x4E86;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x6765;&#x4FEE;&#x4E00;&#x4E0B;&#xFF1A;</p>
<p><strong>boards/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-meta">@login_required</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">reply_topic</span><span class="hljs-params">(request, pk, topic_pk)</span>:</span>
    topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk)
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">&apos;POST&apos;</span>:
        form = PostForm(request.POST)
        <span class="hljs-keyword">if</span> form.is_valid():
            post = form.save(commit=<span class="hljs-keyword">False</span>)
            post.topic = topic
            post.created_by = request.user
            post.save()

            topic.last_updated = timezone.now()  <span class="hljs-comment"># &lt;- &#x8FD9;&#x91CC;</span>
            topic.save()                         <span class="hljs-comment"># &lt;- &#x8FD9;&#x91CC;</span>

            <span class="hljs-keyword">return</span> redirect(<span class="hljs-string">&apos;topic_posts&apos;</span>, pk=pk, topic_pk=topic_pk)
    <span class="hljs-keyword">else</span>:
        form = PostForm()
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">&apos;reply_topic.html&apos;</span>, {<span class="hljs-string">&apos;topic&apos;</span>: topic, <span class="hljs-string">&apos;form&apos;</span>: form})
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x8981;&#x505A;&#x7684;&#x4E8B;&#x662F;&#x9700;&#x8981;&#x63A7;&#x5236;&#x4E00;&#x4E0B;&#x9875;&#x9762;&#x8BBF;&#x95EE;&#x7EDF;&#x8BA1;&#x7CFB;&#x7EDF;&#x3002;&#x6211;&#x4EEC;&#x4E0D;&#x5E0C;&#x671B;&#x76F8;&#x540C;&#x7684;&#x7528;&#x6237;&#x518D;&#x6B21;&#x5237;&#x65B0;&#x9875;&#x9762;&#x7684;&#x65F6;&#x5019;&#x88AB;&#x7EDF;&#x8BA1;&#x4E3A;&#x591A;&#x6B21;&#x8BBF;&#x95EE;&#x3002;&#x4E3A;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4F1A;&#x8BDD;(sessions)&#xFF1A;</p>
<p><strong>boards/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PostListView</span><span class="hljs-params">(ListView)</span>:</span>
    model = Post
    context_object_name = <span class="hljs-string">&apos;posts&apos;</span>
    template_name = <span class="hljs-string">&apos;topic_posts.html&apos;</span>
    paginate_by = <span class="hljs-number">20</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_context_data</span><span class="hljs-params">(self, **kwargs)</span>:</span>

        session_key = <span class="hljs-string">&apos;viewed_topic_{}&apos;</span>.format(self.topic.pk)  <span class="hljs-comment"># &lt;--&#x8FD9;&#x91CC;</span>
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> self.request.session.get(session_key, <span class="hljs-keyword">False</span>):
            self.topic.views += <span class="hljs-number">1</span>
            self.topic.save()
            self.request.session[session_key] = <span class="hljs-keyword">True</span>           <span class="hljs-comment"># &lt;--&#x76F4;&#x5230;&#x8FD9;&#x91CC;</span>

        kwargs[<span class="hljs-string">&apos;topic&apos;</span>] = self.topic
        <span class="hljs-keyword">return</span> super().get_context_data(**kwargs)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_queryset</span><span class="hljs-params">(self)</span>:</span>
        self.topic = get_object_or_404(Topic, board__pk=self.kwargs.get(<span class="hljs-string">&apos;pk&apos;</span>), pk=self.kwargs.get(<span class="hljs-string">&apos;topic_pk&apos;</span>))
        queryset = self.topic.posts.order_by(<span class="hljs-string">&apos;created_at&apos;</span>)
        <span class="hljs-keyword">return</span> queryset
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x4E3B;&#x9898;&#x5217;&#x8868;&#x4E2D;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x66F4;&#x597D;&#x4E00;&#x70B9;&#x7684;&#x5BFC;&#x822A;&#x3002;&#x76EE;&#x524D;&#x552F;&#x4E00;&#x7684;&#x9009;&#x62E9;&#x662F;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x4E3B;&#x9898;&#x6807;&#x9898;&#x5E76;&#x8F6C;&#x5230;&#x7B2C;&#x4E00;&#x9875;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5B9E;&#x8DF5;&#x4E00;&#x4E0B;&#x8FD9;&#x4E48;&#x505A;&#xFF1A;</p>
<p><strong>boards/models.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math
<span class="hljs-keyword">from</span> django.db <span class="hljs-keyword">import</span> models

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Topic</span><span class="hljs-params">(models.Model)</span>:</span>
    <span class="hljs-comment"># ...</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__str__</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">return</span> self.subject

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_page_count</span><span class="hljs-params">(self)</span>:</span>
        count = self.posts.count()
        pages = count / <span class="hljs-number">20</span>
        <span class="hljs-keyword">return</span> math.ceil(pages)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">has_many_pages</span><span class="hljs-params">(self, count=None)</span>:</span>
        <span class="hljs-keyword">if</span> count <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:
            count = self.get_page_count()
        <span class="hljs-keyword">return</span> count &gt; <span class="hljs-number">6</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_page_range</span><span class="hljs-params">(self)</span>:</span>
        count = self.get_page_count()
        <span class="hljs-keyword">if</span> self.has_many_pages(count):
            <span class="hljs-keyword">return</span> range(<span class="hljs-number">1</span>, <span class="hljs-number">5</span>)
        <span class="hljs-keyword">return</span> range(<span class="hljs-number">1</span>, count + <span class="hljs-number">1</span>)
</code></pre>
<p>&#x7136;&#x540E;&#xFF0C;&#x5728; <strong>topics.html</strong> &#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x5B9E;&#x73B0;&#xFF1A;</p>
<p><strong>templates/topics.html</strong></p>
<pre><code class="lang-html">
<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;table table-striped mb-4&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">thead</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;thead-inverse&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Topic<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Starter<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Replies<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Views<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Last Update<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
      {% for topic in topics %}
        {% url &apos;topic_posts&apos; board.pk topic.pk as topic_url %}
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;mb-0&quot;</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{{ topic_url }}&quot;</span>&gt;</span>{{ topic.subject }}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">small</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-muted&quot;</span>&gt;</span>
              Pages:
              {% for i in topic.get_page_range %}
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{{ topic_url }}?page={{ i }}&quot;</span>&gt;</span>{{ i }}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
              {% endfor %}
              {% if topic.has_many_pages %}
              ... <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{{ topic_url }}?page={{ topic.get_page_count }}&quot;</span>&gt;</span>Last Page<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
              {% endif %}
            <span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>{{ topic.starter.username }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>{{ topic.replies }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>{{ topic.views }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>{{ topic.last_updated|naturaltime }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
      {% endfor %}
    <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<p>&#x5C31;&#x50CF;&#x6BCF;&#x4E2A;&#x4E3B;&#x9898;&#x7684;&#x5C0F;&#x5206;&#x9875;&#x4E00;&#x6837;&#x3002;&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x6211;&#x5728; table &#x6807;&#x7B7E;&#x91CC;&#x8FD8;&#x6DFB;&#x52A0;&#x4E86; <code>table-striped</code> &#x7C7B;&#xFF0C;&#x4F7F;&#x5F97;&#x8868;&#x683C;&#x6709;&#x4E00;&#x4E2A;&#x66F4;&#x597D;&#x7684;&#x6837;&#x5F0F;&#x3002;</p>
<p><img src="statics/6-14.png" alt=""></p>
<p>&#x5728;&#x56DE;&#x590D;&#x9875;&#x9762;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x662F;&#x5217;&#x51FA;&#x4E86;&#x6240;&#x6709;&#x7684;&#x56DE;&#x590D;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x9650;&#x5236;&#x5728;&#x6700;&#x8FD1;&#x7684;&#x5341;&#x4E2A;&#x56DE;&#x590D;&#x3002;</p>
<p><strong>boards/models.py</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Topic</span><span class="hljs-params">(models.Model)</span>:</span>
    <span class="hljs-comment"># ...</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_last_ten_posts</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">return</span> self.posts.order_by(<span class="hljs-string">&apos;-created_at&apos;</span>)[:<span class="hljs-number">10</span>]
</code></pre>
<p><strong>templates/reply_topic.html</strong></p>
<pre><code class="lang-html">
{% block content %}

  <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;mb-4&quot;</span> <span class="hljs-attr">novalidate</span>&gt;</span>
    {% csrf_token %}
    {% include &apos;includes/form.html&apos; %}
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-success&quot;</span>&gt;</span>Post a reply<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>

  {% for post in topic.get_last_ten_posts %}  <span class="hljs-comment">&lt;!-- here! --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card mb-2&quot;</span>&gt;</span>
      <span class="hljs-comment">&lt;!-- code suppressed --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  {% endfor %}

{% endblock %}
</code></pre>
<p><img src="statics/6-15.png" alt=""></p>
<p>&#x53E6;&#x4E00;&#x4EF6;&#x4E8B;&#x662F;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x56DE;&#x590D;&#x5E16;&#x5B50;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x662F;&#x4F1A;&#x518D;&#x6B21;&#x5C06;&#x7528;&#x6237;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x7B2C;&#x4E00;&#x9875;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5C06;&#x7528;&#x6237;&#x9001;&#x56DE;&#x5230;&#x6700;&#x540E;&#x4E00;&#x9875;&#x6765;&#x6539;&#x5584;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x5E16;&#x5B50;&#x4E0A;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;ID&#xFF1A;</p>
<p><strong>templates/topic_posts.html</strong></p>
<pre><code class="lang-html">
{% block content %}

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;mb-4&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;reply_topic&apos; topic.board.pk topic.pk %}&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary&quot;</span> <span class="hljs-attr">role</span>=<span class="hljs-string">&quot;button&quot;</span>&gt;</span>Reply<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

  {% for post in posts %}
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;{{ post.pk }}&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card {% if forloop.last %}mb-4{% else %}mb-2{% endif %} {% if forloop.first %}border-dark{% endif %}&quot;</span>&gt;</span>
      <span class="hljs-comment">&lt;!-- code suppressed --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  {% endfor %}

  {% include &apos;includes/pagination.html&apos; %}

{% endblock %}
</code></pre>
<p>&#x8FD9;&#x91CC;&#x7684;&#x91CD;&#x8981;&#x70B9;&#x662F; <code>&lt;div id=&quot;{{ post.pk }}&quot; ...&gt;</code>&#x3002;</p>
<p>&#x7136;&#x540E;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x89C6;&#x56FE;&#x4E2D;&#x50CF;&#x8FD9;&#x6837;&#x4F7F;&#x7528;&#x5B83;&#xFF1A;</p>
<p><strong>boards/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-meta">@login_required</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">reply_topic</span><span class="hljs-params">(request, pk, topic_pk)</span>:</span>
    topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk)
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">&apos;POST&apos;</span>:
        form = PostForm(request.POST)
        <span class="hljs-keyword">if</span> form.is_valid():
            post = form.save(commit=<span class="hljs-keyword">False</span>)
            post.topic = topic
            post.created_by = request.user
            post.save()

            topic.last_updated = timezone.now()
            topic.save()

            topic_url = reverse(<span class="hljs-string">&apos;topic_posts&apos;</span>, kwargs={<span class="hljs-string">&apos;pk&apos;</span>: pk, <span class="hljs-string">&apos;topic_pk&apos;</span>: topic_pk})
            topic_post_url = <span class="hljs-string">&apos;{url}?page={page}#{id}&apos;</span>.format(
                url=topic_url,
                id=post.pk,
                page=topic.get_page_count()
            )

            <span class="hljs-keyword">return</span> redirect(topic_post_url)
    <span class="hljs-keyword">else</span>:
        form = PostForm()
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">&apos;reply_topic.html&apos;</span>, {<span class="hljs-string">&apos;topic&apos;</span>: topic, <span class="hljs-string">&apos;form&apos;</span>: form})
</code></pre>
<p>&#x5728; <strong>topic_post_url</strong> &#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x6700;&#x540E;&#x4E00;&#x9875;&#x6765;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;url&#xFF0C;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x951A;&#x70B9;id&#x7B49;&#x4E8E;&#x5E16;&#x5B50;id&#x7684;&#x5143;&#x7D20;&#x3002;</p>
<p>&#x6709;&#x4E86;&#x8FD9;&#x4E2A;&#xFF0C;&#x8FD9;&#x8981;&#x6C42;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x4E0B;&#x9762;&#x7684;&#x8FD9;&#x4E9B;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#xFF1A;</p>
<p><strong>boards/tests/test_view_reply_topic.py</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SuccessfulReplyTopicTests</span><span class="hljs-params">(ReplyTopicTestCase)</span>:</span>
    <span class="hljs-comment"># ...</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_redirection</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&apos;&apos;&apos;
        A valid form submission should redirect the user
        &apos;&apos;&apos;</span>
        url = reverse(<span class="hljs-string">&apos;topic_posts&apos;</span>, kwargs={<span class="hljs-string">&apos;pk&apos;</span>: self.board.pk, <span class="hljs-string">&apos;topic_pk&apos;</span>: self.topic.pk})
        topic_posts_url = <span class="hljs-string">&apos;{url}?page=1#2&apos;</span>.format(url=url)
        self.assertRedirects(self.response, topic_posts_url)
</code></pre>
<p><img src="statics/6-16.png" alt=""></p>
<p>&#x4E0B;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x6B63;&#x5982;&#x4F60;&#x5728;&#x524D;&#x9762;&#x7684;&#x622A;&#x56FE;&#x4E2D;&#x770B;&#x5230;&#x7684;&#xFF0C;&#x8981;&#x89E3;&#x51B3;&#x5206;&#x9875;&#x65F6;&#x9875;&#x6570;&#x592A;&#x591A;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x8C03;&#x6574; <strong>pagination.html</strong> &#x6A21;&#x677F;&#xFF1A;</p>
<p><strong>templates/includes/pagination.html</strong></p>
<pre><code class="lang-html">
{% if is_paginated %}
  &lt;nav aria-label=&quot;Topics pagination&quot; class=&quot;mb-4&quot;&gt;
    &lt;ul class=&quot;pagination&quot;&gt;
      {% if page_obj.number &gt; 1 %}
        &lt;li class=&quot;page-item&quot;&gt;
          &lt;a class=&quot;page-link&quot; href=&quot;?page=1&quot;&gt;First&lt;/a&gt;
        &lt;/li&gt;
      {% else %}
        &lt;li class=&quot;page-item disabled&quot;&gt;
          &lt;span class=&quot;page-link&quot;&gt;First&lt;/span&gt;
        &lt;/li&gt;
      {% endif %}

      {% if page_obj.has_previous %}
        &lt;li class=&quot;page-item&quot;&gt;
          &lt;a class=&quot;page-link&quot; href=&quot;?page={{ page_obj.previous_page_number }}&quot;&gt;Previous&lt;/a&gt;
        &lt;/li&gt;
      {% else %}
        &lt;li class=&quot;page-item disabled&quot;&gt;
          &lt;span class=&quot;page-link&quot;&gt;Previous&lt;/span&gt;
        &lt;/li&gt;
      {% endif %}

      {% for page_num in paginator.page_range %}
        {% if page_obj.number == page_num %}
          &lt;li class=&quot;page-item active&quot;&gt;
            &lt;span class=&quot;page-link&quot;&gt;
              {{ page_num }}
              &lt;span class=&quot;sr-only&quot;&gt;(current)&lt;/span&gt;
            &lt;/span&gt;
          &lt;/li&gt;
        {% elif page_num &gt; page_obj.number|add:&apos;-3&apos; and page_num &lt; page_obj.number|add:&apos;3&apos; %}
          &lt;li class=&quot;page-item&quot;&gt;
            &lt;a class=&quot;page-link&quot; href=&quot;?page={{ page_num }}&quot;&gt;{{ page_num }}&lt;/a&gt;
          &lt;/li&gt;
        {% endif %}
      {% endfor %}

      {% if page_obj.has_next %}
        &lt;li class=&quot;page-item&quot;&gt;
          &lt;a class=&quot;page-link&quot; href=&quot;?page={{ page_obj.next_page_number }}&quot;&gt;Next&lt;/a&gt;
        &lt;/li&gt;
      {% else %}
        &lt;li class=&quot;page-item disabled&quot;&gt;
          &lt;span class=&quot;page-link&quot;&gt;Next&lt;/span&gt;
        &lt;/li&gt;
      {% endif %}

      {% if page_obj.number != paginator.num_pages %}
        &lt;li class=&quot;page-item&quot;&gt;
          &lt;a class=&quot;page-link&quot; href=&quot;?page={{ paginator.num_pages }}&quot;&gt;Last&lt;/a&gt;
        &lt;/li&gt;
      {% else %}
        &lt;li class=&quot;page-item disabled&quot;&gt;
          &lt;span class=&quot;page-link&quot;&gt;Last&lt;/span&gt;
        &lt;/li&gt;
      {% endif %}
    &lt;/ul&gt;
  &lt;/nav&gt;
{% endif %}
</code></pre>
<p><img src="statics/6-17.png" alt=""></p>
<h3 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h3>
<p>&#x5728;&#x672C;&#x6559;&#x7A0B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5B8C;&#x6210;&#x4E86;<strong>Django board</strong>&#x9879;&#x76EE;&#x5E94;&#x7528;&#x7684;&#x5B9E;&#x73B0;&#x3002;&#x6211;&#x53EF;&#x80FD;&#x4F1A;&#x53D1;&#x5E03;&#x4E00;&#x4E2A;&#x540E;&#x7EED;&#x7684;&#x5B9E;&#x73B0;&#x6559;&#x7A0B;&#x6765;&#x6539;&#x8FDB;&#x4EE3;&#x7801;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4E00;&#x8D77;&#x7814;&#x7A76;&#x5F88;&#x591A;&#x4E8B;&#x60C5;&#x3002;&#x4F8B;&#x5982;&#x6570;&#x636E;&#x5E93;&#x4F18;&#x5316;&#xFF0C;&#x6539;&#x8FDB;&#x7528;&#x6237;&#x754C;&#x9762;&#xFF0C;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x64CD;&#x4F5C;&#xFF0C;&#x521B;&#x5EFA;&#x5BA1;&#x6838;&#x7CFB;&#x7EDF;&#x7B49;&#x7B49;&#x3002;</p>
<p>&#x4E0B;&#x4E00;&#x7BC7;&#x6559;&#x7A0B;&#x5C06;&#x7740;&#x91CD;&#x4E8E;&#x90E8;&#x7F72;&#x3002;&#x5B83;&#x5C06;&#x662F;&#x5173;&#x4E8E;&#x5982;&#x4F55;&#x5C06;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x6295;&#x5165;&#x5230;&#x751F;&#x4EA7;&#x4E2D;&#x4EE5;&#x53CA;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x7684;&#x4E00;&#x4E9B;&#x91CD;&#x8981;&#x7EC6;&#x8282;&#x7684;&#x5B8C;&#x6574;&#x6307;&#x5357;&#x3002;</p>
<p>&#x6211;&#x5E0C;&#x671B;&#x4F60;&#x4F1A;&#x559C;&#x6B22;&#x672C;&#x7CFB;&#x5217;&#x6559;&#x7A0B;&#x7684;&#x7B2C;&#x516D;&#x90E8;&#x5206;&#xFF01;&#x6700;&#x540E;&#x4E00;&#x90E8;&#x5206;&#x5C06;&#x4E8E;&#x4E0B;&#x5468;2017&#x5E74;10&#x6708;16&#x65E5;&#x53D1;&#x5E03;&#x3002;&#x5982;&#x679C;&#x4F60;&#x5E0C;&#x671B;&#x5728;&#x6700;&#x540E;&#x4E00;&#x90E8;&#x5206;&#x53D1;&#x5E03;&#x65F6;&#x6536;&#x5230;&#x901A;&#x77E5;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA2;&#x9605;&#x6211;&#x4EEC;&#x7684;<a href="http://eepurl.com/b0gR51" target="_blank">&#x90AE;&#x4EF6;&#x5217;&#x8868;</a>&#x3002;</p>
<p>&#x8BE5;&#x9879;&#x76EE;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x5728;github&#x4E0A;&#x627E;&#x5230;&#x3002;&#x5F53;&#x524D;&#x72B6;&#x6001;&#x7684;&#x8BE5;&#x9879;&#x76EE;&#x7684;&#x53EF;&#x4EE5;&#x5728;&#x53D1;&#x5E03;&#x6807;&#x7B7E; <strong>v0.6-lw</strong> &#x4E0B;&#x627E;&#x5230;&#x3002;&#x6216;&#x8005;&#x76F4;&#x63A5;&#x70B9;&#x51FB;&#x4E0B;&#x9762;&#x7684;&#x94FE;&#x63A5;&#xFF1A;</p>
<p><a href="https://github.com/sibtc/django-beginners-guide/tree/v0.6-lw" target="_blank">https://github.com/sibtc/django-beginners-guide/tree/v0.6-lw</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ClassBasedViews3.html" class="navigation navigation-prev " aria-label="Previous page: Django入门与实践-第25章：Markdown支持">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Deployment.html" class="navigation navigation-next " aria-label="Next page: Django入门与实践-第27章：项目部署">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Django入门与实践-第26章：个性化设置","level":"1.27","depth":1,"next":{"title":"Django入门与实践-第27章：项目部署","level":"1.28","depth":1,"path":"Deployment.md","ref":"./Deployment.md","articles":[]},"previous":{"title":"Django入门与实践-第25章：Markdown支持","level":"1.26","depth":1,"path":"ClassBasedViews3.md","ref":"./ClassBasedViews3.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["include-codeblock","livereload"],"pluginsConfig":{"include-codeblock":{"check":false,"edit":false,"fixlang":false,"lang":"","template":"default","theme":"chrome","unindent":false},"livereload":{},"highlight":{},"search":{},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"sharing":{"all":["facebook","google","instapaper","twitter","weibo"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"file":{"path":"ClassBasedViews4.md","mtime":"2018-05-13T13:48:46.860Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-13T12:52:49.928Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

